﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using Lswweb.Domain;
using Lswweb.Model;

namespace Lswweb.Controls
{
    public class UserProfile : SkinnedWebControl
    {
        private TextBox tbxName;
        private TextBox tbxMobile;
        private TextBox tbxPhone;
        private TextBox tbxFax;
        private TextBox tbxStreet;
        private TextBox tbxPostCode;
        private SexRadio sexType;
        private TextBox tbxCompanyName;
        private TreeCallBackDropDownList city;

        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
            tbxName=(TextBox)skin.FindControl("tbxName");
            tbxMobile=(TextBox)skin.FindControl("tbxMobile");
            tbxPhone=(TextBox)skin.FindControl("tbxPhone");
            tbxFax=(TextBox)skin.FindControl("tbxFax");
            tbxStreet=(TextBox)skin.FindControl("tbxStreet");
            tbxPostCode=(TextBox)skin.FindControl("tbxPostCode");
            sexType = (SexRadio)skin.FindControl("sexType");
            city = (TreeCallBackDropDownList)skin.FindControl("city");
            tbxCompanyName = (TextBox)skin.FindControl("tbxCompanyName");
        }

        public UserProfileInfo ProfileInfo
        {
            get 
            {
                UserProfileInfo profile = new UserProfileInfo();
                profile.CityId = Convert.ToInt32(city.SelectValue);
                profile.Mobile = tbxMobile.Text.Trim();
                profile.Fax = tbxFax.Text.Trim();
                profile.Name = tbxName.Text.Trim();
                profile.Phone = tbxPhone.Text.Trim();
                profile.PostCode = tbxPostCode.Text.Trim();
                profile.Sex = sexType.SelectedValue;
                profile.Street = tbxStreet.Text.Trim();
                profile.CompanyName = tbxCompanyName.Text.Trim();
                return profile;
            }
            set 
            {
                if (value == null)
                    return;

                this.EnsureChildControls();

                tbxMobile.Text = value.Mobile;
                tbxFax.Text = value.Fax;
                tbxName.Text = value.Name;
                tbxPhone.Text = value.Phone;
                tbxPostCode.Text = value.PostCode;
                tbxStreet.Text = value.Street;

                sexType.SelectedValue = value.Sex;

                city.SelectValue = value.CityId;
                tbxCompanyName.Text = value.CompanyName;
            }
        }

        protected override string DefaultSkinFilename
        {
            get { return "User/UserProfile.ascx"; }
        }
    }
}
